<?php

namespace oa\controllers;

use Yii;
use oa\services\DeliveryCompanyService;

class ExpressController extends BaseController
{

	public function actionIndex()
	{
        if ($this->request->isAjax) {
            return DeliveryCompanyService::getList();
        }
        return $this->fetch();
	}

	public function actionAdd()
	{
		if ($this->request->isPost) {
			$res = DeliveryCompanyService::save($this->request->post());
			if ($res === true) {
				return $this->ok('提交成功');
			}
			return $this->err('提交失败', $res);
        }
		return $this->fetch([], 2);
	}

	public function actionEdit()
	{
		$res = DeliveryCompanyService::save($this->request->post());
		if ($res === true) {
			return $this->ok('提交成功');
		}
		return $this->err($res);
	}

	public function actionDelete()
	{
		if (DeliveryCompanyService::remove($this->input('id'))) {
			return $this->ok('删除成功');
		}
		return $this->err('删除失败');
	}

	public function actionDisable()
	{
		if (DeliveryCompanyService::disable($this->input('id'))) {
			return $this->ok('操作成功');
		}
		return $this->err('操作失败');
	}

	public function actionEnable()
	{
		if (DeliveryCompanyService::enable($this->input('id'))) {
			return $this->ok('操作成功');
		}
		return $this->err('操作失败');
	}

	public function actionCompanyIndex()
	{
        if ($this->request->isAjax) {
            return DeliveryCompanyService::getList();
        }
        return $this->fetch();
	}

	public function actionCompanyAdd()
	{
		if ($this->request->isPost) {
			$res = DeliveryCompanyService::save($this->request->post());
			if ($res === true) {
				return $this->ok('提交成功');
			}
			return $this->err('提交失败', $res);
        }
		return $this->fetch([], 2);
	}

	public function actionCompanyEdit()
	{
		$res = DeliveryCompanyService::save($this->request->post());
		if ($res === true) {
			return $this->ok('提交成功');
		}
		return $this->err($res);
	}

	public function actionCompanyDelete()
	{
		if (DeliveryCompanyService::remove($this->input('id'))) {
			return $this->ok('删除成功');
		}
		return $this->err('删除失败');
	}

	public function actionCompanyDisable()
	{
		if (DeliveryCompanyService::disable($this->input('id'))) {
			return $this->ok('操作成功');
		}
		return $this->err('操作失败');
	}

	public function actionCompanyEnable()
	{
		if (DeliveryCompanyService::enable($this->input('id'))) {
			return $this->ok('操作成功');
		}
		return $this->err('操作失败');
	}
	
}